var header = '<div class="navbar navbar-fixed-top">';
header += '<div class="container-fluid cl">';
header += '<a class="logo navbar-logo f-l mr-10 hidden-xs" href="/console/index.html">Date数据管理系统后台</a> ';
header += '<span class="logo navbar-slogan f-l mr-10 hidden-xs">v1.0</span>';
header += '<nav id="Hui-userbar" class="nav navbar-nav navbar-userbar hidden-xs">';
header += '<ul class="cl">';
header += '<li><a href="/index.html" target="_blank">网站首页</a></li> ';
header += '<li id="roleName"></li>';
header += '<li class="dropDown dropDown_hover">';
header += '<a href="#" class="dropDown_A" id="adminName"> <i class="Hui-iconfont">&#xe6d5;</i></a>';
header += '<ul class="dropDown-menu menu radius box-shadow">';
header += '<li><a href="javascript:;" onClick="myselfinfo()">个人信息</a></li><li><a href="#">切换账户</a></li><li><a href="javascript:void(0);" onclick="logout();">退出</a></li>';
header += '</ul></li>';
header += '<li id="Hui-skin" class="dropDown right dropDown_hover"> <a href="javascript:;" class="dropDown_A" title="换肤"><i class="Hui-iconfont" style="font-size:18px">&#xe62a;</i></a>';
header += '<ul class="dropDown-menu menu radius box-shadow">';
header += '<li><a href="javascript:;" data-val="default" title="默认（黑色）">默认（黑色）</a></li>';
header += '<li><a href="javascript:;" data-val="blue" title="蓝色">蓝色</a></li>';
header += '<li><a href="javascript:;" data-val="green" title="绿色">绿色</a></li>';
header += '<li><a href="javascript:;" data-val="red" title="红色">红色</a></li>';
header += '<li><a href="javascript:;" data-val="yellow" title="黄色">黄色</a></li>';
header += '<li><a href="javascript:;" data-val="orange" title="橙色">橙色</a></li>';
header += '</ul></li>';
header += '</ul></nav>';
header += '</div></div>';

$("#header").append(header);
// 退出登陆
function logout() {
    layer.confirm('纳尼,要退出？', function (index) {
        var storage = window.localStorage;
        var token = storage.getItem("token");
        $.ajax({
            url: '/ajax/login/logout',
            type: 'POST',
            data: {
                "token": token
            },
            dataType: "json",
            beforeSend:function(request){
                request.setRequestHeader("authStr", storage.getItem("userId") + "-" + token);
            },
            success: function (data) {
                if (data == true) {
                    storage.removeItem("edatamenu");
                    storage.removeItem("userId");
                    storage.removeItem("token");
                    window.location.href = "/console/login.html";
                } else {
                    alert("操作失败请稍后重试");
                }
            }
        });
    })
}
var userId = "";
var token = "";
var userInfo = {};
if (!window.localStorage) {
    alert("此浏览器不适用本系统, 推荐使用Chrome浏览器");
    window.location.href = "/console/login.html";
} else {
    var storage = window.localStorage;
    userId = storage.getItem("userId") ? storage.getItem("userId") : "";
    token = storage.getItem("token") ? storage.getItem("token") : "";
    userInfo = JSON.parse(storage.getItem('userInfo'));
}

if (!isNull(token) || !isNull(userId)) {
    // console.log(userId);
    // console.log(token);
    $.ajax({
        type:"POST",
        url: "/ajax/login/islogin",
        data: {
            "userId": userId,
            "token": token,
        },
        dataType: "json",
        success:function(data){
            if (data != true) {
                window.location.href = "/console/login.html";
            }
            return false;
        },
        error:function(data){
            window.location.href = "/console/login.html";
        }
    });
} else {
    window.location.href = "/console/login.html";
}

$("#roleName").html(userInfo.rolename);
$("#adminName").html(userInfo.username);


// //当前时间
// function time() {
// 	var today = new Date()
// 	var y = today.getFullYear();
// 	var mon = today.getMonth() + 1;
// 	var d = today.getDate();
// 	var h = today.getHours()
// 	var m = today.getMinutes()
// 	var s = today.getSeconds()
// 	// add a zero in front of numbers<10
// 	mon = mon < 10 ? "0" + mon : mon;
// 	d = d < 10 ? "0" + d : d;
// 	h = h < 10 ? "0" + h : h;
// 	m = m < 10 ? "0" + m : m;
// 	s = s < 10 ? "0" + s : s;
// 	$(".li_time span").html(y + '-' + mon + '-' + d + "&nbsp;&nbsp;&nbsp;" + h + ":" + m + ":" + s);
// 	t = setTimeout('time()', 1000);
// }
// time();
